package com.sinoeyes.flowdata.service.impl;

import com.sinoeyes.common.core.page.RestPageResult;
import com.sinoeyes.common.core.text.Convert;
import com.sinoeyes.common.vo.BaseVo;
import com.sinoeyes.flowdata.po.FlowPurchaseDataPo;
import com.sinoeyes.flowdata.filter.FlowPurchaseDataFilter;
import com.sinoeyes.flowdata.mapper.FlowPurchaseDataMapper;
import com.sinoeyes.flowdata.service.IFlowPurchaseDataService;
import com.sinoeyes.flowdata.vo.FlowPurchaseDatasVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 标准采购流向Service业务层处理
 * 
 * @author steven.zhang
 * @date 2019-10-10
 */
@Service
public class FlowPurchaseDataServiceImpl implements IFlowPurchaseDataService {
    @Autowired
    private FlowPurchaseDataMapper flowPurchaseDataMapper;

    /**
     * 查询标准采购流向
     * 
     * @param id 标准采购流向ID
     * @return 标准采购流向
     */
    @Override
    public FlowPurchaseDatasVo selectFlowPurchaseDatasById(String id)
    {
        return BaseVo.copyPo2Vo(flowPurchaseDataMapper.selectFlowPurchaseDatasById(id), FlowPurchaseDatasVo.class);
    }

    /**
     * 新增标准采购流向
     * 
     * @param flowPurchaseDataVo 标准采购流向
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int insertFlowPurchaseDatas(FlowPurchaseDatasVo flowPurchaseDataVo)
    {
        return flowPurchaseDataMapper.insertFlowPurchaseDatas(BaseVo.copyVo2Po(flowPurchaseDataVo, FlowPurchaseDataPo.class));
    }

    /**
     * 修改标准采购流向
     * 
     * @param flowPurchaseDataVo 标准采购流向
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int updateFlowPurchaseDatas(FlowPurchaseDatasVo flowPurchaseDataVo)
    {
        return flowPurchaseDataMapper.updateFlowPurchaseDatas(BaseVo.copyVo2Po(flowPurchaseDataVo, FlowPurchaseDataPo.class));
    }

    /**
     * 删除标准采购流向对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int deleteFlowPurchaseDatasByIds(String ids)
    {
        return flowPurchaseDataMapper.deleteFlowPurchaseDatasByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除标准采购流向信息
     * 
     * @param id 标准采购流向ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int deleteFlowPurchaseDatasById(String id)
    {
        return flowPurchaseDataMapper.deleteFlowPurchaseDatasById(id);
    }

    /**
     * 根据过滤条件查询
     * @param flowPurchaseDataFilter
     * @return
     */
    @Override
    public RestPageResult<FlowPurchaseDatasVo> selectFlowPurchaseDatasByFilter(FlowPurchaseDataFilter flowPurchaseDataFilter) {
        flowPurchaseDataFilter.startPage();
        List<FlowPurchaseDataPo> flowPurchaseDataPos = flowPurchaseDataMapper.selectFlowPurchaseDatasByFilter(flowPurchaseDataFilter);
        RestPageResult pageResult = flowPurchaseDataFilter.getPageResult(flowPurchaseDataPos);
        return BaseVo.copyPo2Vo(pageResult, FlowPurchaseDatasVo.class);
    }
}
